
#!/usr/bin/env node

const path = require('path')
const fs = require('fs')
const flag = false;

let args = process.argv.slice(2)

if (args.length === 0) {
    filesDisplay(process.cwd())
}else {
    let curDir = args[0].split('-')[1]
    filesDisplay(path.join(__dirname, curDir))
}
function filesDisplay(url) {
    let dirArr = fs.readdirSync(url)

    dirArr.forEach(item => {
        let childPath = path.join(url, item) 
        if (fs.statSync(childPath).isFile()) {       
            let ext = path.extname(childPath).slice(1)
            let { size } = fs.statSync(childPath)
            process.stdout.write(`${item}---${ext}---${size}\n`)
        }else { 
            if (flag) {
                filesDisplay(childPath)
            }else{
                return
            }
        }
    })
}